<?php

declare(strict_types=1);

namespace App\Fastapp\Model;

use Hyperf\Database\Model\SoftDeletes;
use Mine\MineModel;

/**
 * @property int $id 主键
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property string $deleted_at 删除时间
 * @property string $name 名称
 * @property int $start_at 开始时间
 * @property int $end_at 结束时间
 * @property int $fixed 永久有效
 * @property array $cover 位置图片
 * @property array $cover_theme 图片主题
 * @property int $status 1显示
 * @property int $sort 排序
 * @property int $object_type 数据类型1链接2视频3分享4文章
 * @property int $object_id 关联数据
 * @property string $url 分享链接
 * @property array $title 分享标题
 * @property array $image 分享封面
 * @property array $desc 分享描述
 * @property array $content 分享内容
 * @property string $remark 备注
 * @property string $code 调用代码
 */
class FastappAd extends MineModel
{
    use SoftDeletes, FileTrait;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'fastapp_ad';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'created_at', 'updated_at', 'deleted_at', 'name', 'start_at', 'end_at', 'fixed', 'cover', 'cover_theme', 'status', 'sort', 'object_type', 'object_id', 'url', 'title', 'image', 'desc', 'content', 'remark', 'code'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'start_at' => 'integer', 'end_at' => 'integer', 'fixed' => 'integer', 'cover' => 'array', 'cover_theme' => 'array', 'status' => 'integer', 'sort' => 'integer', 'object_type' => 'integer', 'object_id' => 'integer', 'title' => 'array', 'image' => 'array', 'desc' => 'array', 'content' => 'array'];

    public function setStartAtAttribute($v): void
    {
        if ($v) $this->attributes['start_at'] = strtotime($v);
    }

    public function getStartAtAttribute($v): ?string
    {
        if ($v) return date('Y-m-d H:i:s', $v);
        return null;
    }

    public function setEndAtAttribute($v): void
    {
        if ($v) $this->attributes['end_at'] = strtotime($v);
    }

    public function getEndAtAttribute($v): ?string
    {
        if ($v) return date('Y-m-d H:i:s', $v);
        return null;
    }
}
